class Title
  def initialize
    @titlescreen = Images['media/pnr.png', false]
    @alpha = 0
    @color = Gosu::Color.new(@alpha,255,255, 255)
    @full = false
    @temp = 0
    @done = false
    @done2 = true
    @draw = true
  end

  def update
    if @full and @alpha==0
        $game = nil
        $game = Frontend.new
        @done = true
    end    
    if !@done
      if @alpha < 254 and !@full
        @alpha += 2
      elsif @alpha == 254 and @temp==0
        @full = true
        @temp += 2
      elsif @full and @temp <= 100
        @temp += 1
      else
        if @alpha > 0
        @alpha -= 2
        end
      end
    end
    @color = Gosu::Color.new(@alpha,255,255, 255)
    if @done
      destroy
    end
    if @draw ==false
      #$game = nil
      $game = Frontend.new
      destroy
    end
    if @done2 == false
      @draw = false
    end
  end
  
  def button_down(id)
    if id == Gosu::Button::KbReturn
      @done2 = false
    end  
  end
  
  def draw
    if @draw
      @titlescreen.draw_rot(320, 240, 0, 0, 0.5,0.5, 0.5,0.5, @color)
    end
 end
 
 def destroy
    @titlescreen = nil
    @color = nil
    @alpha = nil
    @full = nil
    @temp = nil
    @done = nil
    GC.start
 end
end